[Lazarus] Inserting enum type into Postgresql

Michael Van Canneyt michael at freepascal.org
Fri May 15 17:26:30 CEST 2015



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.


More information about the Lazarus mailing list