[Lazarus] Inserting enum type into Postgresql

"Leonardo M. Ramé" l.rame at griensu.com
Fri May 15 17:37:37 CEST 2015


El 15/05/15 a las 12:26, Michael Van Canneyt escibió:
>
>
> On Fri, 15 May 2015, "Leonardo M. Ramé" wrote:
>
>> Hi, I need to insert a value into a custom type column in a PostgreSql
>> database.
>>
>> The type was created using this:
>>
>> create type doc_type as enum('pdf', 'rtf', 'html', 'doc', 'docx',
>> 'xls', 'xlsx', 'txt');
>>
>> To insert a field into a table with one column of that type, I use:
>>
>> var
>>  lQuery: TSqlQuery;
>>
>> begin
>>  ...
>>  lQuery.Sql.Text := 'insert into documents(document_name,
>> document_type) values(:name, :type)';
>>  lQuery.ParamByName('type').AsString := 'txt';
>>  ...
>>
>> I get "Primary Error: column "document_type" is of type doc_type but
>> expression is of type text". How can I cast this?.
>
> I would think
> insert into documents(document_name, document_type)  values(:name,
> (:type)::doc_type )';
> ?
>
> Michael.
>
>

Yes, that was the solution.

Leonardo.




More information about the Lazarus mailing list